package edu.gatech.oad.mule;

import java.awt.Point;
import java.awt.Rectangle;
import java.io.Serializable;

import edu.gatech.oad.mule.view.interfaces.RenderableZone;
import edu.gatech.oad.mule.model.GameStateMachine.GameState;

/**
 * This class represents a zone on one of the Map instances.  A Zone is just a 
 * generic term for an area on the Map.
 *
 * @author Brendan McGarry, Dale Avery, D'Miria Collins, Natasha Parekh, Jaemin Park
 * @version %I%, %G%
 */
public abstract class Zone implements RenderableZone, Serializable {
	
	private static final long serialVersionUID = -7284038984463403844L;
	
	protected Rectangle zone;
	
	/**
	 * This constructor configures a new Zone object
	 *
	 * @param x The x coordinate of the zone
	 * @param y The y coordinate of the zone
	 * @param width The width of the zone
	 * @param height The height of the zone
	 */
	public Zone(int x, int y, int width, int height){
		zone = new Rectangle(x, y, width, height);
	}//end constructor

	/**
	 * This constructor creates a new zone out of an
	 * already configured rectanglular zone
	 *
	 * @param zone The rectangular zone
	 */
	public Zone(Rectangle zone){
		this.zone = zone;
	}//end constructor

	/**
	 * @param p The player to check
	 * @return Whether or not the player is inside this zone
	 */
	public boolean contains(Player p){
		return contains(p.getLocation());
	}//end method contains

	/**
	 * @param p The point to check
	 * @return Whether or not the point is inside this zone
	 */
	public boolean contains(Point p){
		return zone.contains(p);
	}//end method contains

	/**
	 * @param x The x-coordinate to check
	 * @param y The y-coordinate to check
	 * @return Whether or not the (x,y) coordinate is in this zone
	 */
	public boolean contains(int x, int y){
		return contains(new Point(x, y));
	}//end method contains

	/**
	 * @return The java.awt.Rectangle that represents this zone
	 */
	public Rectangle getZone(){
		return zone;
	}//end method getZone

	/**
	 * This method defines what happens when a player interacts
	 * with this zone
	 *
	 * @param p The Player who is interacting with this zone
	 * @param phase The current phase the game is in
	 * @param round The current round the game is in (0 = 1st round)
	 * @param time The amount of time (in milliseconds) remaining in p's turn
	 */
	public abstract void interact(Player p, GameState phase, int round, int time);

	//==============================
	//	RenderableZone
	//==============================

	@Override
	public int getHeight(){
		return ((int)(zone.getHeight()));
	}//end method getX

	@Override
	public int getWidth(){
		return ((int)(zone.getWidth()));
	}//end method getX
	
	@Override
	public int getX(){
		return ((int)(zone.getX()));
	}//end method getX

	@Override
	public int getY(){
		return ((int)(zone.getY()));
	}//end method getX

}//end class Zone
